package com.muki.succ.web.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.muki.succ.core.Manager;
import com.muki.succ.web.service.ManagerService;
import com.muki.succ.web.service.SpiderService;
import com.muki.succ.web.service.UriService;

@RestController
public class ThemeController {

	@Autowired private UriService uriService;
	
	@Autowired private SpiderService spiderService;
	
	@Autowired private ManagerService managerService;
	
	class Theme {
		
		//主题名
		private String topic;
		
		//起始urk
		private List<String> start_Url;
		
		//爬虫数量
		private int SpiderNum;
		
		//存储路径
		private String save_path;

		public String getTopic() {
			return topic;
		}

		public void setTopic(String topic) {
			this.topic = topic;
		}

		public List<String> getStart_Url() {
			return start_Url;
		}

		public void setStart_Url(List<String> start_Url) {
			this.start_Url = start_Url;
		}

		public int getSpiderNum() {
			return SpiderNum;
		}

		public void setSpiderNum(int spiderNum) {
			SpiderNum = spiderNum;
		}

		public String getSave_path() {
			return save_path;
		}

		public void setSave_path(String save_path) {
			this.save_path = save_path;
		}
		
		
	}
	
	
	@RequestMapping(value="themes")
	public List<Theme> getTheme() {
		List<Theme> themes = new ArrayList<>();
		List<Manager> managers = managerService.getManagerNames();
		if(managers==null)
			return null;
		for(Manager key:managers) {
			Theme t = new Theme();
			t.setTopic(key.getTopic());;
			t.setStart_Url(uriService.getUsingUrls().get(key.getTopic()));
			t.setSpiderNum(key.getCount());
			t.setSave_path("...");
			themes.add(t);
		}
		return themes;
	}
}
